package com.depthsdata.coe.api;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import com.depthsdata.coe.dao.BusinessProcessDAOQueryBean;
import com.depthsdata.coe.service.BusinessProcessBean;
import com.ourteam.frame.web.AbstractSearchModel;

public class BusinessProcessSearchBean extends AbstractSearchModel<BusinessProcessDAOQueryBean> {

	private Long businessUnitId;

	private String businessProcessName;

	private String[] status;

	public String[] getStatus() {
		return status;
	}

	public void setStatus(String[] status) {
		this.status = status;
	}

	public Long getBusinessUnitId() {
		return businessUnitId;
	}

	public void setBusinessUnitId(Long businessUnitId) {
		this.businessUnitId = businessUnitId;
	}

	public String getBusinessProcessName() {
		return businessProcessName;
	}

	public void setBusinessProcessName(String businessProcessName) {
		this.businessProcessName = businessProcessName;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return BusinessProcessBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(BusinessProcessDAOQueryBean queryBean) throws Exception {

		BusinessProcessDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (businessUnitId != null && businessUnitId.longValue() != 0) {
			criteria.andBusinessUnitIdEqualTo(businessUnitId);
		}

		if (StringUtils.isNoneBlank(this.businessProcessName)) {
			criteria.andBusinessProcessNameLike(businessProcessName);
		}

		if (ArrayUtils.isNotEmpty(this.status)) {
			criteria.andStatusIn(status);
		}

	}

}
